﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.Odbc;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Videoer : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int NewRowcount = 0;
        int x = 0;
        DivResults.InnerHtml = "<table cellpadding=\"2\" callspacing=\"4\"><tr>";

        ReviewerMySql SQL = new ReviewerMySql();
        OdbcDataReader TopReader = SQL.ExecuteReader("SELECT V2_Spil.Titel, V2_Spil.SpilID, V2_SpilVideo.Link, V2_SpilVideo.Titel, V2_SpilVideo.ID FROM V2_SpilVideo JOIN V2_Spil ON V2_Spil.SpilID = V2_SpilVideo.SpilID GROUP BY V2_Spil.SpilID ORDER BY V2_SpilVideo.ID DESC LIMIT 4");

        string LinkRemake = "";

        while (TopReader.Read())
        {
            LinkRemake = UI.LinkMake.LinkVideo(TopReader[4].ToString(), TopReader[0].ToString() + " " + TopReader[3].ToString()); 
            NewRowcount++;
            OdbcDataReader ScreenReader = SQL.ExecuteReader("SELECT * FROM V2_Screenshots WHERE SpilID = '" + TopReader[1].ToString() + "' LIMIT 1");
            ScreenReader.Read();
            DivResults.InnerHtml += "<td onclick=\"javascript:window.location='" + LinkRemake + "';\" style=\"border:1px solid black; background-color:#CCCCCC; cursor:pointer;\"><img style=\"border:1px solid #666666;\" src=\"screenshots/" + ScreenReader["Filnavn"].ToString() + "\" width=\"260\" height=\"180\"><br /><b>" + TopReader[0].ToString() + "</b><br />" + TopReader[3].ToString() +"</td>";
            if(NewRowcount == 2) 
            {
                DivResults.InnerHtml += "</tr><tr>";
            }
        }
        divList.InnerHtml = "<table width=\"100%\" style=\"border-top:1px solid #666666;\">";
        OdbcDataReader MainReader = SQL.ExecuteReader("SELECT V2_Spil.Titel, V2_Spil.SpilID, V2_SpilVideo.Link, V2_SpilVideo.Titel, V2_SpilVideo.ID FROM V2_SpilVideo JOIN V2_Spil ON V2_Spil.SpilID = V2_SpilVideo.SpilID GROUP BY V2_Spil.SpilID ORDER BY V2_SpilVideo.ID DESC LIMIT 4, 24");
        while (MainReader.Read())
        {
            LinkRemake = UI.LinkMake.LinkVideo(MainReader[4].ToString(), MainReader[0].ToString() + " " + MainReader[3].ToString()); 
        
            if (x == 0)
            {
                divList.InnerHtml += "<tr><td class=\"TDrowTwo\"><a href=\"" + LinkRemake + "\">" + MainReader[0].ToString() + " - " + MainReader[3].ToString() + "</a></td></tr>";
                x++;
            }
            else
            {
                divList.InnerHtml += "<tr><td><a href=\"" + LinkRemake +  "\">" + MainReader[0].ToString() + " - " + MainReader[3].ToString() + "</a></td></tr>";
                x = 0;
            }
        }
        divList.InnerHtml += "</table>";

        DivResults.InnerHtml += "</tr></table>";
        //HtmlMeta HeaderDescription = new HtmlMeta();
        //HeaderDescription.Name = "description";
        //HeaderDescription.Content = "Videoer, trailer og teaser til spil";
        //this.Header.Controls.Add(HeaderDescription);
    }
}
